package leetCode.hw.math;

public class HJ82Solution implements HJ82 {

    @Override
    public String aiJi(String str) {
        StringBuilder result = new StringBuilder();
        String[] s = str.split("/");
        int a = Integer.parseInt(s[0]);
        int b = Integer.parseInt(s[1]);
        while (a != 1) {
            if (b % a == 0) {
                b = b / a;
                a = 1;
                continue;
            }
            if (b % (a - 1) == 0) {
                result.append("1/" + b / (a - 1) + "+");
                a = 1;
            }
            else {
                int c;
                c = b / a + 1;
                a = a - b % a;
                b = b * c;
                result.append("1/").append(c).append("+");
            }
        }
        result.append("1/").append(b);
        return result.toString();
    }

}
